﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShippingID;
using BL;

namespace ShippingID.Controllers
{ 
    public class ClienteController : Controller
    {
     //   private ShippingID.Models.Cliente.Cliente3DBContext db = new ShippingID.Models.Cliente.Cliente3DBContext();
        private ServiceGeral _service;

        public ClienteController()
        {
            _service = new ServiceGeral();
        }
        //
        // GET: /Cliente/

        public ViewResult Index()
        {
            return View(_service.RetornarTodos<Modelo.Cliente>());
        }

        //
        // GET: /Cliente/Details/5

        public ViewResult Details(int id)
        {
            return View(_service.RetornarPorID<Modelo.Cliente>(id));
        }

        //
        // GET: /Cliente/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Cliente/Create

        [HttpPost]
        public ActionResult Create(Modelo.Cliente cliente)
        {
            if (ModelState.IsValid)
            {
                _service.Gravar< Modelo.Cliente>(cliente);
                return RedirectToAction("Index");  
            }

            return View(cliente);
        }
        
        //
        // GET: /Cliente/Edit/5
 
        public ActionResult Edit(int id)
        {
          //  Cliente cliente = db.Cliente.Find(id);
            return View(_service.RetornarPorID<Modelo.Cliente>(id));
        }

        //
        // POST: /Cliente/Edit/5

        [HttpPost]
        public ActionResult Edit(Modelo.Cliente cliente)
        {
            if (ModelState.IsValid)
            {
                _service.Gravar < Modelo.Cliente>(cliente);
                return RedirectToAction("Index");
            }
            return View(cliente);
        }

        //
        // GET: /Cliente/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(_service.RetornarPorID < Modelo.Cliente>(id));
        }

        //
        // POST: /Cliente/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            _service.Excluir<Modelo.Cliente>(id);
            return RedirectToAction("Index");
        }
    }
}